<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <title>canvas</title>
    <style>
        canvas{
            background:#eee;
        }
        div{
            color: #000;
            background: #ddd;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div id="cons">2</div>
    <canvas id="canvas" width="500" height="500"></canvas>
    <script src='../js/utils.js'></script>
    <script src='../js/arrow.js'></script>
    <script>
        window.onload = function(){
            var canvas = document.getElementById("canvas");
            var context = canvas.getContext('2d');
            canvas.width = document.body.clientWidth;
            var centerX = canvas.width/2;
            var centerY = canvas.height/2;
            
            // 传入canvas,获取鼠标在canvas上移动是的坐标
            var mouse = utils.captureTouch(canvas);

            // 新建一个arrow对象
            var arrow = new Arrow();

            // 将arrow的坐标设置为canvas的中心
            arrow.x = centerX;
            arrow.y = centerY;

            // 动画循环函数
            (function drawFrame(){
                window.requestAnimationFrame(drawFrame,canvas);
                context.clearRect(0,0,canvas.width,canvas.height);

                // 获取dy，dx值
                var dx = mouse.x - arrow.x;
                var dy = mouse.y -arrow.y;

                //设置旋转角度
                arrow.rotation = Math.atan2(dy,dx);
                //调用draw方法
                arrow.draw(context);
            })();

           
        }
    </script>
</body>
</html>
<!-- 
 /*function add(event){
                console.log("mouser down")
            }
            //canvas.addEventListener('mousedown',add,false);
            //canvas.addEventListener('touchstart',add,false)
            //canvas.removeEventListener('mousedown',add,false);
            mouse = utils.captureMouse(canvas)

            canvas.addEventListener('mousedown',function(event){
                console.log(mouse.x,mouse.y)
                document.getElementById("cons").innerHTML = mouse.x+" --- "+mouse.y
            })

            // 键盘事件
            window.addEventListener('keydown',function(event){
                console.log(utils.capturnkey(event))

            },false)*/
-->